package com.code.leetcode._202503;

/**整数转化成罗马数字**/
public class NumConvertRom {

    static int[] val = new int[]{1000,900,500,400,100,90,50,40,10,9,5,4,1};
    static String[] str = new String[]{"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
    public static String CovertRom(int num) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < val.length && num >0; i++) {
            int cv = val[i];//穷举 val
            String cs = str[i];//穷举 str
            while (num >= cv){
                sb.append(cs);
                num -= cv;
            }
        }
        return sb.toString();
    }


}
